'use strict';

angular.module('com.dcos.app').controller('TemplateCreateController',function($window,$scope,$uibModalInstance,reload,TemplateService) {
  var vm = this;

  vm.curProjectId=$window.sessionStorage.getItem("curProjectId");

  vm.template={
    "p_id":"",
    "t_name":"",
    "project_id":vm.curProjectId,
    "description":"",
    "status":"1",
    "create_user":"44"
  };
  
  vm.pipelineData=[];

  vm.getList = function () { 
    TemplateService.getPipelineList(vm.curProjectId).then(function (response) {debugger;
      if(response.data.querylist!=null){
        vm.pipelineData=response.data.querylist;
        vm.template.p_id=vm.pipelineData[0].p_id;
      }
    });
  }
  vm.getList();
  vm.ok = function () {
    TemplateService.saveByPipeLine(vm.template).then(function (response) {
      reload();
      $uibModalInstance.dismiss('cancel');
    });  
  }

  vm.cancel = function () {
    $uibModalInstance.dismiss('cancel');
  };
});
